package com.zzyl.nursing.controller.member;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.dto.DeviceDataDto;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.dto.FamilyMemberElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceDataVo;
import com.zzyl.nursing.vo.DeviceVo;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    @Autowired
    private IDeviceService deviceService;

    @Autowired
    IDeviceDataService deviceDataService;

    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    /**
     * 新增老人家属关联
     */
    @PostMapping("add")
    @ApiOperation("新增老人家属关联")
    public AjaxResult add(@ApiParam(value = "老人家属关联对象", required = true) @RequestBody FamilyMemberElderDto familyMemberElderDto) {
        return toAjax(familyMemberElderService.insertFamilyMemberElder(familyMemberElderDto));
    }

    /**
     * 查询客户老人关联列表
     */
    @ApiOperation("查询客户老人关联列表")
    @GetMapping("/list-by-page")
    public R list(FamilyMemberElderDto familyMemberElderDto) {
        startPage();
        List<FamilyMemberElderVo> list = familyMemberElderService.selectFamilyMemberElderList(familyMemberElderDto);
        return R.ok(list);
    }

    /**
     * 查询客户老人关联列表
     */
    @ApiOperation("查询客户老人关联列表")
    @GetMapping("/my")
    public R my() {
        List<FamilyMemberElderVo> list = familyMemberElderService.selectMy();
        return R.ok(list);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    public AjaxResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request){

        return deviceService.queryDevicePropertyStatus(request);
    }

    /**
     * 按天统计查询指标数据
     */
    @ApiOperation("查询客户老人关联列表")
    @GetMapping("/queryDeviceDataListByDay")
    public R queryDeviceDataListByDay(DeviceDataDto deviceDataDto) {

        List<DeviceDataVo> list = deviceDataService.queryDeviceDataListByDay(deviceDataDto);
        return R.ok(list);
    }


    /**
     * 按周统计查询指标数据
     */
    @ApiOperation("按周统计查询指标数据")
    @GetMapping("/queryDeviceDataListByWeek")
    public R queryDeviceDataListByWeek(DeviceDataDto deviceDataDto) {
        List<DeviceDataVo> list = deviceDataService.queryDeviceDataListByWeek(deviceDataDto);
        return R.ok(list);
    }

    /**
     * 获取客户老人关联详细信息
     */
    @ApiOperation("获取客户老人关联详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "客户老人关联ID", required = true)
                              @PathVariable("id") Long id) {
        return success(familyMemberElderService.selectFamilyMemberElderById(id));
    }


    /**
     * 修改客户老人关联
     */
    @ApiOperation("修改客户老人关联")
    @PutMapping
    public AjaxResult edit(@ApiParam(value = "客户老人关联实体")
                           @RequestBody FamilyMemberElder familyMemberElder) {
        return toAjax(familyMemberElderService.updateFamilyMemberElder(familyMemberElder));
    }

    /**
     * 删除客户老人关联
     */
    @ApiOperation("删除客户老人关联")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(familyMemberElderService.deleteFamilyMemberElderByIds(ids));
    }
}
